package com.hk.yajin.function.index;

import android.content.Context;
import android.graphics.Color;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.hk.developmentlib.utills.StringHelper;
import com.hk.developmentlib.utills.UiUtil;
import com.hk.yajin.R;
import com.hk.yajin.model.Message;

import java.util.List;

/**
 * https://github.com/CymChad/BaseRecyclerViewAdapterHelper
 */
public class IndexMessageAdapter extends BaseQuickAdapter<Message, BaseViewHolder> {

    public IndexMessageAdapter(List<Message> datas, Context ct) {
        super(R.layout.list_item_index_message, datas);
    }

    @Override
    protected void convert(final BaseViewHolder helper, Message item) {

        helper.setText(R.id.tv_time, StringHelper.friendlyPubTime(item.getCreate_time() * 1000L));


        if (item.getMail_attachs() != null && item.getMail_attachs().size() > 0) {
            helper.setVisible(R.id.iv_attach, true);
        } else {
            helper.setVisible(R.id.iv_attach, false);
        }

        final TextView textView = helper.getView(R.id.tv_content);
        if (!TextUtils.isEmpty(item.getContent())) {  //内容
            textView.setText(item.getContent());
        } else {
            textView.setText("");
        }

        if (!TextUtils.isEmpty(item.getColor())) {
            textView.setTextColor(Color.parseColor(item.getColor()));
        } else {
            textView.setTextColor(UiUtil.getColor(R.color.black_222));
        }

        textView.post(new Runnable() {
            @Override
            public void run() {
                final int line = textView.getLineCount();
                if (line > 3) {
                    textView.setMaxLines(3);
                    helper.addOnClickListener(R.id.tv_content);
                    textView.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            if (textView.getLineCount() == 3) {
                                textView.setMaxLines(line);
                                //textView.setText(finalText);
                            } else {
                                textView.setMaxLines(3);
                                //textView.setText(msp);
                                //设置图片
                            }
                        }
                    });
                }
            }
        });
        helper.addOnClickListener(R.id.iv_attach);
        helper.addOnClickListener(R.id.ctv_zan);
    }


}
